package com.example.peibei.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.dingtao.common.bean.Agree;
import com.dingtao.common.bean.BillRecord;
import com.dingtao.common.core.DataCall;
import com.dingtao.common.core.WDActivity;
import com.dingtao.common.core.exception.ApiException;
import com.example.peibei.R;
import com.example.peibei.service.presenter.AgreePresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class UserAgreeActivity extends WDActivity {
    @BindView(R.id.fullWebView)
    WebView webView;
    private String type;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_user_agree;
    }

    @Override
    protected void initView() {
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
        webView.setWebViewClient(new WebViewClient());

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        type = bundle.getString("type");
        AgreePresenter agreePresenter = new AgreePresenter(new AgreeCall());
        agreePresenter.reqeust();
    }

    @OnClick(R.id.iv_back)
    public void back(){
        finish();
    }

    class AgreeCall implements DataCall<Agree> {

        @Override
        public void success(Agree data, Object... args) {
            if (type.equals("userAgree")){
                webView.loadUrl(data.getUserAgree());
            }else{
                webView.loadUrl(data.getCompanyPolicy());
            }
        }

        @Override
        public void fail(ApiException e, Object... args) {

        }
    }


    @Override
    protected void destoryData() {

    }
}
